<?php 
namespace app\manager\controller;

use app\admin\model\Admins;


Class Set extends Base
{
   

   public function info(){

        $data = Admins::table('wolive_service')->where('level','<>','super_manager')->paginate(8);
        foreach ($data as $v) {
            $clo_data = json_encode($v);
            $v['json'] = $clo_data;
        }

        $page = $data->render();
        $this->assign('page', $page);
        $this->assign('lister', $data);
        $this->assign('title','客服管理');
       
        return $this->fetch();
   }

   public function change(){
       $post = $this->request->post();

       Admins::table('wolive_business')->where(['business_id' => $post['business_id']])->update(['state'=>$post['type']]);

       return true;
   }

    public function saveexp(){
        $post = $this->request->post();

        Admins::table('wolive_business')->where(['business_id' => $post['business_id']])->update(['exp_timestamp'=>strtotime($post['exp_time'])]);

        return true;
    }

   public function delete(){
       $post = $this->request->post();
   	 $res =Admins::table('wolive_service')->where('service_id',$post['id'])->find();

   	 if($res['level'] == 'manager'){
   	 	$result =Admins::table('wolive_service')->where('parent_id',$post['id'])->whereOr('service_id',$post['id'])->delete();
   	 }else{
   	 	$result =Admins::table('wolive_service')->where('service_id',$post['id'])->delete();
   	 }

     $data=['code'=>0,'msg'=>'success','data'=>$result];
       
     return $data;

   }
 
	
}
